package com.yequan.hbb.presenter;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.yequan.hbb.entries.DynamicEntries;
import com.yequan.hbb.model.DynamicModel;
import com.yequan.hbb.view.DynamicView;

import retrofit2.Response;

/**
 * Created by DingLong on 2016/10/13.
 */

public class DynamicPresenter extends MVPPresenter<DynamicView<DynamicEntries>, DynamicModel> implements DynamicModel.DynamicCallback {
    private Context context;
    private DynamicModel dynamicModel;

    public DynamicPresenter(Context context) {
        this.context = context;
    }

    @Override
    public DynamicModel createModel() {
        dynamicModel = new DynamicModel(this);
        return dynamicModel;
    }

    public void getData(int pageIndex, int pageSize) {
        dynamicModel.getData(pageIndex,pageSize,true);
    }

    @Override
    public void onResponse(Response<DynamicEntries> response) {
        getView().showDynamic(response.body());
    }

    @Override
    public void onFailure(Throwable t) {
        t.printStackTrace();
        Log.e("自定义标签", "类名==DynamicPresenter" + "方法名==onFailure=====:" + "错误"+t.toString());
        Toast.makeText(context,"网络加载失败",Toast.LENGTH_SHORT).show();
    }
}
